﻿using System;
using System.Collections.Generic;
using Color = System.Drawing.Color;
using SwinGame;

namespace Gundam_2._0_Alpha.src
{
    public class Movement: CharacterAction
    {
        public enum Direction
        {
            Left,
            Right,
            Up,
            Down
        } 

        private Direction dir;
        
        public Movement(Character c, bool persistant, int row, int colEnd, int count, int lockoutLevel, Direction dir)
            :base(c, persistant, row, colEnd, count, lockoutLevel)
        {
            this.dir = dir;
        }

        public override void DoAction(GameController gc)
        {
            switch (dir)
            {
                case Direction.Right: MoveRight();
                    break;
                case Direction.Left: MoveLeft();
                    break;
                case Direction.Down: MoveDown();
                    break;
                case Direction.Up: MoveUp();
                    break;
            }
            Reset(gc);
        }

        private void MoveRight()
        {
            if (c.ObjectSprite.X + c.ObjectSprite.Width-110 > GlobalConst.ScreenWidth) return;
            c.ObjectSprite.X += c.StatModifier.SpeedMultiplier;
            if (Input.KeyDown(KeyCode.vk_RCTRL)) return;
            if (c.State == GlobalConst.SpriteState.transAmWest)
                c.State = GlobalConst.SpriteState.transAmEast;
            else if (c.State == GlobalConst.SpriteState.normalWest)
                c.State = GlobalConst.SpriteState.normalEast;
        }

        private void MoveLeft()
        {
            if (c.ObjectSprite.X < -90) return;
            c.ObjectSprite.X -= c.StatModifier.SpeedMultiplier;
            if (Input.KeyDown(KeyCode.vk_RCTRL)) return;
            if (c.State == GlobalConst.SpriteState.transAmEast)
                c.State = GlobalConst.SpriteState.transAmWest;
            else if (c.State == GlobalConst.SpriteState.normalEast)
                c.State = GlobalConst.SpriteState.normalWest;
            
        }

        private void MoveUp()
        {
            if (c.ObjectSprite.Y < 60) return;
            c.ObjectSprite.Y -= c.StatModifier.SpeedMultiplier;
        }

        private void MoveDown()
        {
            if (c.ObjectSprite.Y + c.ObjectSprite.Height-50 > GlobalConst.ScreenHeight) return;
            c.ObjectSprite.Y += c.StatModifier.SpeedMultiplier;
        }

        public override void Reset(GameController gc)
        {
            GlobalConst.Utils.ActivateAnimationRow(c.ObjectSprite, row + c.offSetSpriteRow(), colEnd, count);
        }
    }
}
